package com.ruoyi.project.hcy.administrations.util;


import com.ruoyi.project.hcy.administrations.domain.*;
import com.ruoyi.project.hcy.administrations.service.*;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Component;


/**
 * @ClassName ApprovingUtil
 * @Author 金刚芭比
 * @Date 2020/9/19 15:03
 * @Version 1.0
 *
 *  审批的操作流程封装类
 *
 */
@Component
public class ApproveDisAgreeUtil {
    @Autowired
    private IApproveService approveService;
    @Autowired
    private IDimissionService dimissionService;//离职
    @Autowired
    private IInviteService inviteService; //入职
    @Autowired
    private IPostingService postingService;  //职位调整
    @Autowired
    private ITrainService trainService;  // 培训
    //不同意申请的业务处理
    public int DisAgreeUtil(Integer ids){
        Dimission dimission = null;
        Invite invite = null;
        Posting posting = null;
        Train train = null;
        //根据拿到的id查询数据
        Approve approve = approveService.selectApproveById(ids);
        //Approve{approveId=4, approveName='小钱', approveTitle='小钱申请离职', approveStatus='待审批..', approveType='离职申请'}
        int dispass = 0;
        if ("离职申请".equals(approve.getApproveType())){
            dimission = new Dimission();
            dimission.setDimissionName(approve.getApproveName());
            dimission.setDimissionStatus("已审批");
            dimissionService.updateDimissionStatus(dimission);
            dispass = updateAppStatus(approve);
        }else if ("招聘申请".equals(approve.getApproveType())){
            invite = new Invite();
            invite.setInviteName(approve.getApproveName());
            invite.setInviteStatus("已审批");
            inviteService.updateInviteStatus(invite);
            dispass = updateAppStatus(approve);
        }else if ("职位调整申请".equals(approve.getApproveType())){
            posting = new Posting();
            posting.setPostingName(approve.getApproveName());
            posting.setPostingStatus("已审批");
            postingService.updatePostingStatus(posting);
            dispass = updateAppStatus(approve);
        }else {
            train = new Train();
            train.setTrainName(approve.getApproveName());
            train.setTrainStatus("已审批");
            trainService.updateTrainStatus(train);
            dispass = updateAppStatus(approve);
        }
        return dispass;
    }

    public int updateAppStatus(Approve approve){
        Approve app = new Approve();
        app.setApproveName(approve.getApproveName());
        app.setApproveStatus("已审批");
        app.setApproveType(approve.getApproveType());
        System.out.println(app);
        return approveService.updateApproveStatus(app);
    }
}
